﻿using System;
using System.Collections.Generic;

namespace Host
{
	public abstract class IComponents
	{
		public const long TICK2SECOND = 10000000;

		public IComponents()
		{
			Name = GetType().Name;
			TypeName = GetType().Name;
			ComponentsType = ComponentsType.Data;
		}

		/// <summary>
		/// 获取组件类型
		/// </summary>
		/// <returns>The type.</returns>
		public virtual ComponentsType ComponentsType { get; set; }

		/// <summary>
		/// 获取类型
		/// </summary>
		/// <returns>The type name.</returns>
		public virtual string TypeName { get; set; }

		/// <summary>
		/// 获取名称
		/// </summary>
		/// <returns>The name.</returns>
		public virtual string Name { get; set; }

		/// <summary>
		/// 宿主
		/// </summary>
		/// <value>The host.</value>
		public virtual Host Host { get; set; }

		/// <summary>
		/// 获取同组下的其他组件
		/// </summary>
		/// <returns>The same grop components.</returns>
		/// <param name="ctype">Ctype.</param>
		/// <typeparam name="T">The 1st type parameter.</typeparam>
		public T GetSameGropComponents<T>(string ctype) where T : IComponents
		{
			return Host != null ? Host.GetComponents<T>(ctype) : default(T);
		}

		/// <summary>
		/// Gets all same grop components.
		/// </summary>
		/// <returns>The all same grop components.</returns>
		public IEnumerable<IComponents> GetAllSameGropComponents()
		{
			return Host != null ? Host.GetAllComponents() : null;
		}

		/// <summary>
		/// 销毁内容
		/// </summary>
		/// <value><c>true</c> if destroy me; otherwise, <c>false</c>.</value>
		public bool DestroyMe { get; set; }

		/// <summary>
		/// 上次更新时间
		/// </summary>
		/// <value>The last run time.</value>
		public long LastRunTime { get; protected set; }

		/// <summary>
		/// 下次运行时间
		/// </summary>
		/// <value>The next run time.</value>
		public long NextRunTime { get; protected set; }

		/// <summary>
		/// 创建组件时
		/// </summary>
		public virtual void OnAdd() { }

		/// <summary>
		/// 组件进入时
		/// </summary>
		public virtual void OnEnter() { }

		/// <summary>
		/// 组件进入完成时
		/// </summary>
		public virtual void OnEnterEnd() { }

		/// <summary>
		/// 组件退出时
		/// </summary>
		public virtual void OnExit() { }

		/// <summary>
		/// 组件移除时
		/// </summary>
		public virtual void OnRemove() { }

		/// <summary>
		/// 更新
		/// </summary>
		public virtual void Update() { }
	}
}
